package com.tbit.uqbike.client.service.impl;


import com.tbit.uqbike.client.dao.core.QuickReplyDao;
import com.tbit.uqbike.client.pojo.QuickReply;
import com.tbit.uqbike.client.service.QuickReplyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 快捷回复表(QuickReply)表服务实现类
 *
 * @author shanyong.mo
 * @since 2025-02-11 10:09:05
 */
@Service("quickReplyService")
public class QuickReplyServiceImpl implements QuickReplyService {
    @Resource
    private QuickReplyDao quickReplyDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public QuickReply queryById(Integer id) {
        return this.quickReplyDao.queryById(id);
    }

    /**
     * @description: 批量查询
     * @param: idList 查询的id集合
     * @return: java.util.List<QuickReply>
     */
    @Override
    public List<QuickReply> queryByIds(List<Integer> idList) {
        return this.quickReplyDao.queryByIds(idList);
    }


    /**
     * 分页查询
     *
     * @param quickReply 筛选条件
     * @param pageNum    页码
     * @param pageSize   每页数据量
     * @return 查询结果
     */
    @Override
    public List<QuickReply> queryByPage(QuickReply quickReply, Integer pageNum,
                                        Integer pageSize, String search) {
        return this.quickReplyDao.queryAllByLimit(quickReply,
                Objects.nonNull(pageNum) && Objects.nonNull(pageSize) ? (pageNum - 1) * pageSize : null, pageSize, search);
    }


    /**
     * 查询总数
     *
     * @param quickReply 筛选条件
     * @param search     搜索内容
     * @return 查询结果
     */
    @Override
    public Integer queryCount(QuickReply quickReply, String search) {
        return this.quickReplyDao.count(quickReply, search);
    }

    /**
     * 新增数据
     *
     * @param quickReply 实例对象
     * @return 实例对象
     */
    @Override
    public QuickReply insert(QuickReply quickReply) {
        Date now = new Date();
        quickReply.setCreateTime(now);
        quickReply.setUpdateTime(now);
        this.quickReplyDao.insert(quickReply);
        return quickReply;
    }

    /**
     * 修改数据
     *
     * @param quickReply 实例对象
     * @return 实例对象
     */
    @Override
    public QuickReply update(QuickReply quickReply) {
        Date now = new Date();
        quickReply.setUpdateTime(now);
        this.quickReplyDao.update(quickReply);
        return this.queryById(quickReply.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.quickReplyDao.deleteById(id) > 0;
    }

    /**
     * 新增数据（会判断null字段，null字段不插入）
     *
     * @param quickReply 实例对象
     * @return 实例对象
     */
    @Override
    public QuickReply insertCheckNull(QuickReply quickReply) {
        Date now = new Date();
        quickReply.setUpdateTime(now);
        this.quickReplyDao.insertCheckNull(quickReply);
        return quickReply;
    }

    /**
     * 更新数据（会判断null字段，null字段不更新）
     *
     * @param quickReply 实例对象
     * @return 实例对象
     */
    @Override
    public QuickReply updateCheckNull(QuickReply quickReply) {
        Date now = new Date();
        quickReply.setUpdateTime(now);
        this.quickReplyDao.updateCheckNull(quickReply);
        return this.queryById(quickReply.getId());
    }
}
